/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrameUsuario.java
 *
 * Created on 13/09/2011, 22:45:02
 */
package br.com.GUI.cadastro;

import br.com.classes.Nivel;
import br.com.classes.Usuario;
import br.com.dao.NivelDao;
import br.com.dao.UsuarioDao;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

/**
 *
 * @author Kauane
 */
public class FrameUsuario extends javax.swing.JFrame {

    /** Creates new form FrameUsuario */
    int cod_usuario;
    int num = 0;

    public FrameUsuario() {
        initComponents();
        CarregarNivel();
        CarregarUsuario();
        
 
        

    }

        public class LetraMaiuscula extends PlainDocument {  
     @Override  
     public void insertString(int offset, String str, AttributeSet attr)  
     throws BadLocationException {  
       super.insertString(offset, str.toUpperCase(), attr);  
     }    
}  
    
    public void CarregarNivel() // lista os níveis das cidades da tabela do BD Nível.
    {

        NivelDao ndao = new NivelDao();
        List<Nivel> lista = ndao.ListarNivel();

        for (Nivel n : lista) {
            jComboBox1.addItem(n.getNivel());
        }
    }

    public void CarregarUsuario() {
        UsuarioDao udao = new UsuarioDao();
        List<Usuario> lista = udao.ListarUsuario();
        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaUsuario.getModel();
        modelo.setRowCount(0);

        for (Usuario u : lista) {
            String i;
            if (u.getNivel() == 1) { //Administrador
                i = "Administrador"; //atribuindo o valor "Administrador" para que seja possível mostrar na tabela
            } else {
                i = "Usuario";
            }

            modelo.addRow(new Object[]{u.getCod_usuario(), u.getNome_usuario(), u.getLogin(), i});
        }

        jTableConsultaUsuario.setModel(modelo);
    }

    public void CarregarUsuarioLetra() {
        String usuario = jTextField11.getText();

        UsuarioDao udao = new UsuarioDao();
        List<Usuario> lista = udao.ProcurarUsuarioLetra(usuario);

        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaUsuario.getModel();
        modelo.setRowCount(0);

        for (Usuario u : lista) {
            String i;
            if (u.getNivel() == 1) { //Administrador
                i = "Administrador"; //atribuindo o valor "Administrador" para que seja possível mostrar na tabela
            } else {
                i = "Usuario";
            }
            modelo.addRow(new Object[]{u.getCod_usuario(), u.getNome_usuario(), u.getLogin(), i});
        }

        jTableConsultaUsuario.setModel(modelo);
    }

    public void BuscarLimiteAnterior() {
        num = num - 10;

        UsuarioDao udao = new UsuarioDao();
        List<Usuario> lista = udao.BuscarLimite(num);

        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaUsuario.getModel();
        modelo.setRowCount(0);

        for (Usuario u : lista) {
            String nivel = null;
            if (u.getNivel() == 1) {
                nivel = "Administrador";
            } else {
                nivel = "Usuario";
            }
            modelo.addRow(new Object[]{u.getCod_usuario(), u.getNome_usuario(), u.getLogin(), nivel});
        }
        jTableConsultaUsuario.setModel(modelo);
                        if(lista.size()<10){
    jButtonVoltar.setEnabled(false);
    }
    }

    public void BuscarLimiteProximo() {
        num = num + 10;

        UsuarioDao udao = new UsuarioDao();
        List<Usuario> lista = udao.BuscarLimite(num);

        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaUsuario.getModel();
        modelo.setRowCount(0);

        for (Usuario u : lista) {
            String nivel = null;
            if (u.getNivel() == 1) {
                nivel = "Administrador";
            } else {
                nivel = "Usuario";
            }
            modelo.addRow(new Object[]{u.getCod_usuario(), u.getNome_usuario(), u.getLogin(), nivel});
        }
        jTableConsultaUsuario.setModel(modelo);
                        if(lista.size()<10){
    jButtonAvancar.setEnabled(false);
    }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTableConsultaUsuario = new javax.swing.JTable();
        jLabel12 = new javax.swing.JLabel();
        jTextField11 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField1 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jButtonAvancar = new javax.swing.JButton();
        jButtonEditar = new javax.swing.JButton();
        jButtonVoltar = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButtonCadastrar = new javax.swing.JButton();
        jLabelUsuario = new javax.swing.JLabel();
        jButtonLimparUsuario = new javax.swing.JButton();

        setTitle("Cadastro de Usuário");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTableConsultaUsuario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Nome", "Login", "Nivel"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableConsultaUsuario.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTableConsultaUsuario);
        jTableConsultaUsuario.getColumnModel().getColumn(0).setMinWidth(70);
        jTableConsultaUsuario.getColumnModel().getColumn(0).setPreferredWidth(70);
        jTableConsultaUsuario.getColumnModel().getColumn(0).setMaxWidth(70);
        jTableConsultaUsuario.getColumnModel().getColumn(1).setMinWidth(220);
        jTableConsultaUsuario.getColumnModel().getColumn(1).setPreferredWidth(220);
        jTableConsultaUsuario.getColumnModel().getColumn(1).setMaxWidth(200);
        jTableConsultaUsuario.getColumnModel().getColumn(2).setMinWidth(150);
        jTableConsultaUsuario.getColumnModel().getColumn(2).setPreferredWidth(150);
        jTableConsultaUsuario.getColumnModel().getColumn(2).setMaxWidth(150);
        jTableConsultaUsuario.getColumnModel().getColumn(3).setMinWidth(100);
        jTableConsultaUsuario.getColumnModel().getColumn(3).setPreferredWidth(100);
        jTableConsultaUsuario.getColumnModel().getColumn(3).setMaxWidth(100);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 257, 537, 187));

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel12.setText("Pesquisa Nome:");
        getContentPane().add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 24, -1, -1));

        jTextField11.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField11KeyReleased(evt);
            }
        });
        getContentPane().add(jTextField11, new org.netbeans.lib.awtextra.AbsoluteConstraints(418, 21, 101, -1));

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/search[1].png"))); // NOI18N
        getContentPane().add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(523, 21, -1, -1));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados do Usuário"));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Nome:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Login:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Senha:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("Nível:");

        jTextField2.setDocument(new LetraMaiuscula());

        jTextField3.setDocument(new LetraMaiuscula());

        jTextField1.setDocument(new LetraMaiuscula());
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField3))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(7, 7, 7)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 51, 530, -1));

        jButtonAvancar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/next[2].png"))); // NOI18N
        jButtonAvancar.setBorder(null);
        jButtonAvancar.setContentAreaFilled(false);
        jButtonAvancar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/next[2]over.png"))); // NOI18N
        jButtonAvancar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAvancarActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonAvancar, new org.netbeans.lib.awtextra.AbsoluteConstraints(347, 213, -1, -1));

        jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil.png"))); // NOI18N
        jButtonEditar.setBorder(null);
        jButtonEditar.setContentAreaFilled(false);
        jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil[2]over.png"))); // NOI18N
        jButtonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditarActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonEditar, new org.netbeans.lib.awtextra.AbsoluteConstraints(254, 213, -1, -1));

        jButtonVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/back[2].png"))); // NOI18N
        jButtonVoltar.setBorder(null);
        jButtonVoltar.setContentAreaFilled(false);
        jButtonVoltar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/back[2]over.png"))); // NOI18N
        jButtonVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVoltarActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonVoltar, new org.netbeans.lib.awtextra.AbsoluteConstraints(223, 213, -1, -1));

        jButton3.setBackground(null);
        jButton3.setForeground(null);
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete[5].png"))); // NOI18N
        jButton3.setBorder(null);
        jButton3.setBorderPainted(false);
        jButton3.setContentAreaFilled(false);
        jButton3.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete[5]over.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(312, 212, -1, 26));

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/refresh.png"))); // NOI18N
        jButton8.setBorder(null);
        jButton8.setContentAreaFilled(false);
        jButton8.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/refresh[2]over.png"))); // NOI18N
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(281, 213, -1, -1));

        jButtonCadastrar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCadastrar.setText("Cadastrar");
        jButtonCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCadastrarActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonCadastrar, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 200, 93, 41));

        jLabelUsuario.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabelUsuario.setText("Usuario");
        getContentPane().add(jLabelUsuario, new org.netbeans.lib.awtextra.AbsoluteConstraints(28, 21, -1, -1));

        jButtonLimparUsuario.setText("Limpar");
        jButtonLimparUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLimparUsuarioActionPerformed(evt);
            }
        });
        getContentPane().add(jButtonLimparUsuario, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 215, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonAvancarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAvancarActionPerformed
        BuscarLimiteProximo();
        jButtonVoltar.setEnabled(true);
}//GEN-LAST:event_jButtonAvancarActionPerformed

    private void jButtonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEditarActionPerformed

         if (jTableConsultaUsuario.getSelectedRow() >= 0) {
            if (jLabelUsuario.getText() == "Usuario") {
                jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/removeicon.png")));
                jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/removeicon.png")));
        int k = jTableConsultaUsuario.getSelectedRow();
        cod_usuario = (Integer) jTableConsultaUsuario.getValueAt(k, 0);

        UsuarioDao udao = new UsuarioDao();
        Usuario u = udao.PesquisarUsuario(cod_usuario);

        jTextField1.setText(u.getNome_usuario());
        jTextField2.setText(u.getLogin());
        jTextField3.setText(u.getSenha());
        jLabelUsuario.setText("Alterar Usuario");
        jButtonCadastrar.setText("Alterar");
        //pegando o nível selecionado, de acordo com a pesquisa (PesquisarUsuario)
        if (u.getNivel() == 1) {              // se o nível for 1, ele é Administrador
            jComboBox1.setSelectedIndex(0); // e o combobox deve ficar selecionado no item do Adm
        } else if (u.getNivel() == 2) {          // se o nível for 2, ele é usuário
            jComboBox1.setSelectedIndex(1); // e o combobox deve ficar selecionado no item Usuario
        }
            }else{
                        jTextField1.setText("");
                        jTextField2.setText("");
                        jTextField3.setText("");
                        jLabelUsuario.setText("Usuario");
                        jButtonCadastrar.setText("Cadastrar");
                          jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil.png")));
                jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil[2]over.png")));
                
            }} else {
            JOptionPane.showMessageDialog(this, "Favor selecionar um Usuario para ser alterado");
        }
        

}//GEN-LAST:event_jButtonEditarActionPerformed

    private void jButtonVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVoltarActionPerformed
        // TODO add your handling code here:
        BuscarLimiteAnterior();
        jButtonAvancar.setEnabled(true);
}//GEN-LAST:event_jButtonVoltarActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

        if (jTableConsultaUsuario.getSelectedRow() >= 0) {
        int linha = jTableConsultaUsuario.getSelectedRow();
        Object[] OPTIONS = {"Sim", "Não"};
        String nome_usuario = jTableConsultaUsuario.getValueAt(linha, 1).toString();

        UsuarioDao dao = new UsuarioDao();
        Usuario u = new Usuario();
        u.setNome_usuario(nome_usuario);

        try {
            int I = JOptionPane.showOptionDialog(null, "Tem certeza que deseja excluir o registro?", "Excluir", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, OPTIONS, OPTIONS[0]);
            if (I == JOptionPane.YES_OPTION) {

                dao.DeletarUsuario(u);
                JOptionPane.showMessageDialog(this, "Excluído com sucesso!");
                CarregarUsuario();
            }
        } catch (Exception e) {
            System.out.println("1 - " + e.getMessage());
        }}else {
           JOptionPane.showMessageDialog(null, "Por favor selecione um usuario para ser excluido!");
       }   
}//GEN-LAST:event_jButton3ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        CarregarUsuario();
        jButtonAvancar.setEnabled(true);
}//GEN-LAST:event_jButton8ActionPerformed

    private void jButtonCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCadastrarActionPerformed

        if (jTextField1.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Favor preencher os campos!");
        } else {
            try {

                if (jLabelUsuario.getText().equals("Usuario")) {
                    Usuario u = new Usuario();
                    UsuarioDao udao = new UsuarioDao();
                    int codusu = udao.UltimoCodUsu();

                  //  DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel();

                    u.setNome_usuario(jTextField1.getText());
                    u.setLogin(jTextField2.getText());
                    u.setSenha(jTextField3.getText());

                    if (jComboBox1.getSelectedIndex() == 0) { //se o Index do ComboBox selecionado for 0, ele é Administrador
                        u.setNivel(1);                      //sendo assim, o Nível deve ser gravado com 1
                    } else {                                //se o Index do ComboBox for diferente, ele é Usuário
                        u.setNivel(2);                      //neste caso o Nível deve ser gravado com o nº 2
                    }

                    udao.CadastrarUsuario(u);
                    CarregarUsuario();

                    JOptionPane.showMessageDialog(this, "Cadastro realizado");
                    jTextField1.setText("");
                    jTextField2.setText("");
                    jTextField3.setText("");
                } else {
                    Object[] OPTIONS = {"Sim", "Não"};

                    int I = JOptionPane.showOptionDialog(null, "Tem certeza que deseja alterar o registro?", "Alterar", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, OPTIONS, OPTIONS[0]);
                    if (I == JOptionPane.YES_OPTION) {
                        Usuario u = new Usuario();
                        u.setCod_usuario(cod_usuario);
                        u.setNome_usuario(jTextField1.getText());
                        u.setLogin(jTextField2.getText());
                        u.setSenha(jTextField3.getText());
                        UsuarioDao udao = new UsuarioDao();
                        udao.AlterarUsuario(u);

                        jTextField1.setText("");
                        jTextField2.setText("");
                        jTextField3.setText("");
                        jLabelUsuario.setText("Usuario");
                        jButtonCadastrar.setText("Cadastrar");
                        jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil[2]over.png")));
                        jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil.png")));

                    }
                    CarregarUsuario();
                }
            } catch (Exception e) {
                System.out.println("1 - " + e.getMessage());
            }
        }
    }//GEN-LAST:event_jButtonCadastrarActionPerformed

    private void jTextField11KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField11KeyReleased
        // TODO add your handling code here:
        CarregarUsuarioLetra();
    }//GEN-LAST:event_jTextField11KeyReleased

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
  String a = jTextField1.getText(); 
  System.out.println(a);
  String[] asDuas = a.split("4");  
  System.out.println(asDuas[0]);  
  System.out.println(asDuas[1]);  
  //System.out.println(asDuas[2]);  
  jTextField1.setText(asDuas[0]);
  jTextField2.setText(asDuas[1]);
  //jTextField3.setText(asDuas[2]);
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jButtonLimparUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLimparUsuarioActionPerformed
        // TODO add your handling code here:
                jTextField1.setText("");
                    jTextField2.setText("");
                    jTextField3.setText("");
    }//GEN-LAST:event_jButtonLimparUsuarioActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrameUsuario().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButtonAvancar;
    private javax.swing.JButton jButtonCadastrar;
    private javax.swing.JButton jButtonEditar;
    private javax.swing.JButton jButtonLimparUsuario;
    private javax.swing.JButton jButtonVoltar;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabelUsuario;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableConsultaUsuario;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField11;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration//GEN-END:variables
}
